//
//  TT_BaseViewController.m
//  BaseProject
//
//  Created by 王洋 on 2020/4/21.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "TT_BaseViewController.h"

@interface TT_BaseViewController ()

@end

@implementation TT_BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"viewDidLoad: %@", self.class);
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.tintColor = UIColorHex(0x333333);
    self.view.backgroundColor = UIColorHex(0xf7f7f7);
    [self makeUI];
    [self handleEvent];
    [self bindViewModel];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 去除黑线
    UIImageView *navBarHairlineImageView = [self findLineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (UIImageView *)findLineImageViewUnder:(UIView *)view {
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findLineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

#pragma mark 全局导航item的返回按钮，如果单个vc想改，可以在vc里面调这个方法
- (UIBarButtonItem *)rt_customBackItemWithTarget:(id)target action:(SEL)action {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"public_back_black"] forState:UIControlStateNormal];
    btn.frame = CGRectMake(0, 0, 50, 44);
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [[UIBarButtonItem alloc] initWithCustomView:btn];
}

- (void)makeUI {}
- (void)handleEvent {}
- (void)bindViewModel {}
@end
